/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commands;

import Persistence.ConversationFactory;
import Persistence.ConversationPersistence;
import java.io.File;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import servidorped.User;

/**
 *
 * @author Micosil
 */
public class showchat implements Command {

    @Override
    public boolean execute(String[] stringlist, User user) {
        ConversationPersistence convp = ConversationFactory.getConversationPersistence();
        System.out.println(stringlist[1]);
        if (!convp.conversationExists(stringlist[1]) || !convp.isUserInConversation(stringlist[1], user.getUserName())) {
            user.getUserSender().setToSend("Conversation not found.");
            return false;
        } else {
            List<String> conversation = convp.retrieveConversation(stringlist[1]);
            for (String oneString : conversation) {
                user.getUserSender().setToSend(oneString);
            }
            Logger.getGlobal().log(Level.INFO, "User {0} was shown conversation {1}", new Object[]{user.getUserName(), stringlist[1]});
            return true;
        }
    }
}
